<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ page import="com.util.SessionUtils"%>
<%@ page import="java.util.*"%>
<%@ page import="com.dao.GrantVerifyDAO"%>
<%
	GrantVerifyDAO dao = new GrantVerifyDAO();
	try{
		List list = dao.queryFunctions(request);
%>
<html>
<head>
<META http-equiv=Pragma content=no-cache>
<META http-equiv=Cache-Control content=no-cache>
<META http-equiv=Expires content=0>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>left</title>
<link  href="../style/css/main.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../style/scripts/private.js"  language="JavaScript"></script>
<script type="text/javascript">
	document.onkeydown   =   function(){   
		if   (event.keyCode==8){   
         event.cancelBubble = true;  
  		 event.returnValue   =   false;   
  		 return   false;   
         }
     } </script>
<style type="text/css">
body {
	background: url(../style/images/leftbg.jpg) no-repeat;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #E9F8FE;
	scrollbar-face-color: #ECF5FE;           /*立体滚动条凸出部分的颜色*/
	scrollbar-highlight-color: #FFFFFF;      /*滚动条空白部分的颜色*/
	scrollbar-shadow-color: #ebf7fc;         /*立体滚动条阴影的颜色*/
	scrollbar-3dlight-color: #f1f1f1;        /*立体滚动条亮边的颜色*/
	scrollbar-arrow-color:  #0C62AF;          /*上下按钮上三角箭头的颜色*/
	scrollbar-track-color: #ECF5FE;          /*滚动条的基本颜色*/
	scrollbar-darkshadow-color: #a5c6e7;     /*立体滚动条强阴影的颜色*/
	scrollbar-BASE-color: #000000;   
	scrollbar-width:      10px;  
	CURSOR: url(style/images/mouse.cur);
	overflow-x:hidden;
	overflow-y:auto;
}

a {   COLOR:#ff0000; text-decoration:    none;	}
a:hover { color:#ff0000;   text-decoration:    none;	}
</style>
<script language="JavaScript1.2">
scores = new Array(20);var numTotal=0;NS4 = (document.layers) ? 1 : 0;IE4 = (document.all) ? 1 : 0;ver4 = (NS4 || IE4) ? 1 : 0;if (ver4) {    with (document) {        write("<STYLE TYPE='text/css'>");        if (NS4) {            write(".parent {position:absolute; visibility:visible}");            write(".child {position:absolute; visibility:visible}");            write(".regular {position:absolute; visibility:visible}")        }        else {            write(".child {display:none}")        }        write("</STYLE>");    }}function getIndex(el) {    ind = null;    for (i=0; i<document.layers.length; i++) {        whichEl = document.layers[i];        if (whichEl.id == el) {            ind = i;            break;        }    }    return ind;}function arrange() {    nextY = document.layers[firstInd].pageY +document.layers[firstInd].document.height;    for (i=firstInd+1; i<document.layers.length; i++) {        whichEl = document.layers[i];        if (whichEl.visibility != "hide") {            whichEl.pageY = nextY;            nextY += whichEl.document.height;        }    }}function initIt(){    if (!ver4) return;    if (NS4) {        for (i=0; i<document.layers.length; i++) {            whichEl = document.layers[i];            if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";       }        arrange();    }    else {        divColl = document.all.tags("DIV");        for (i=0; i<divColl.length; i++) {            whichEl = divColl(i);            if (whichEl.className == "child") whichEl.style.display = "none";        }    }}function expandIt(el) {	if (!ver4) return;    if (IE4) {        whichEl1 = eval(el + "Child");		for(i=1;i<=numTotal;i++){			whichEl = eval(scores[i] + "Child");			if(whichEl!=whichEl1) {				whichEl.style.display = "none";			}		}        whichEl1 = eval(el + "Child");        if (whichEl1.style.display == "none") {            whichEl1.style.display = "block";        }        else {            whichEl1.style.display = "none";        }    }    else {        whichEl = eval("document." + el + "Child");		for(i=1;i<=numTotal;i++){			whichEl = eval("document." + scores[i] + "Child");			if(whichEl!=whichEl1) {				whichEl.visibility = "hide";			}		}        if (whichEl.visibility == "hide") {            whichEl.visibility = "show";        }        else {            whichEl.visibility = "hide";        }        arrange();    }}onload = initIt;
</script>
<script language=JavaScript>
// Arrays for nodes and icons
var nodes		= new Array();;
var openNodes	= new Array();
var icons		= new Array(18);
var imgid = "";
var modName = "";
var modURL = "";

 var http_request = false;
	   var requestUrl = "";

       function send_request(url) {//初始化、指定处理函数、发送请求的函数

              http_request = false;

              //开始初始化XMLHttpRequest对象

              if(window.XMLHttpRequest) { //Mozilla 浏览器


                     http_request = new XMLHttpRequest();

                     if (http_request.overrideMimeType) {//设置MiME类别

                            http_request.overrideMimeType("text/xml");

                     }

              }

              else if (window.ActiveXObject) { // IE浏览器


                     try {

                            http_request = new ActiveXObject("Msxml2.XMLHTTP");

                     } catch (e) {

                            try {

                                   http_request = new ActiveXObject("Microsoft.XMLHTTP");

                            } catch (e) {}

                     }

              }

              if (!http_request) { // 异常，创建对象实例失败


                     window.alert("不能创建XMLHttpRequest对象实例.");

                     return false;

              }

              http_request.onreadystatechange = processRequest;

              // 确定发送请求的方式和URL以及是否同步执行下段代码

              http_request.open("post", url, true);

              http_request.send(null);

       }

       // 处理返回信息的函数


    function processRequest() {

        if (http_request.readyState == 4) { // 判断对象状态


            if (http_request.status == 200) { // 信息已经成功返回，开始处理信息


				if(http_request.responseText==1){
					//window.open('<%=request.getContextPath()%>/' + requestUrl,'mainFrame');
					requestUrl = requestUrl.indexOf("?") == -1?(requestUrl + "?"):(requestUrl + "&");
					window.parent.document.all.mainFrame.src=requestUrl + "datetime=" + new Date().getTime().toString();
				}

            } else { //页面不正常


                alert("You Request Page is Error!");

            }

        }

    }

function userCheck(url,name) {
	requestUrl=url;	
    send_request('removeSessionAttribute.jsp');
}	

// Loads all icons that are used in the tree
function preloadIcons() {
	icons[0] = new Image();
	icons[0].src = "tree/image/img/plus.gif";
	icons[1] = new Image();
	icons[1].src = "tree/image/img/plusbottom.gif";
	icons[2] = new Image();
	icons[2].src = "tree/image/img/minus.gif";
	icons[3] = new Image();
	icons[3].src = "tree/image/img/minusbottom.gif";
	icons[4] = new Image();
	icons[4].src = "tree/image/img/folder"+imgid+".gif";
	icons[5] = new Image();
	icons[5].src = "tree/image/img/folderopen"+imgid+".gif";
}
// Create the tree
function createTree(arrName, startNode, openNode,imageid,modelName,modelURL) {
	imgid = imageid;
	modName = modelName;
	modURL = modelURL;
	nodes = arrName;
	if (nodes.length > 0) {
		preloadIcons();
		if (startNode == null) startNode = 0;
		if (openNode != 0 || openNode != null) setOpenNodes(openNode);
	
		//document.write("<a href=\"" + modURL + "\"  target=mainFrame><img src=\"tree/image/img/base"+imgid+".gif\" align=\"absbottom\" alt=\"\" border=\"0\" />&nbsp;&nbsp;"+modName+"<br /></a>");
	    document.write("<a href=\"javascript:userCheck('" + modURL + "','" + modName + "');\"><img src=\"tree/image/img/base"+imgid+".gif\" align=\"absbottom\" alt=\"\" border=\"0\" />&nbsp;&nbsp;"+modName+"<br /></a>");
		var recursedNodes = new Array();
		addNode(startNode, recursedNodes);
	}
}
// Returns the position of a node in the array
function getArrayId(node) {
	for (i=0; i<nodes.length; i++) {
		var nodeValues = nodes[i].split("|");
		if (nodeValues[0]==node) return i;
	}
}
// Puts in array nodes that will be open
function setOpenNodes(openNode) {
	for (i=0; i<nodes.length; i++) {
		var nodeValues = nodes[i].split("|");
		if (nodeValues[0]==openNode) {
			openNodes.push(nodeValues[0]);
			setOpenNodes(nodeValues[1]);
		}
	} 
}
// Checks if a node is open
function isNodeOpen(node) {
	for (i=0; i<openNodes.length; i++)
		if (openNodes[i]==node) return true;
	return false;
}
// Checks if a node has any children
function hasChildNode(parentNode) {
	for (i=0; i< nodes.length; i++) {
		var nodeValues = nodes[i].split("|");
		if (nodeValues[1] == parentNode) return true;
	}
	return false;
}
// Checks if a node is the last sibling
function lastSibling (node, parentNode) {
	var lastChild = 0;
	for (i=0; i< nodes.length; i++) {
		var nodeValues = nodes[i].split("|");
		if (nodeValues[1] == parentNode)
			lastChild = nodeValues[0];
	}
	if (lastChild==node) return true;
	return false;
}
// Adds a new node in the tree
function addNode(parentNode, recursedNodes) {
	for (var i = 0; i < nodes.length; i++) {

		var nodeValues = nodes[i].split("|");
		if (nodeValues[1] == parentNode) {
			
			var ls	= lastSibling(nodeValues[0], nodeValues[1]);
			var hcn	= hasChildNode(nodeValues[0]);
			var ino = isNodeOpen(nodeValues[0]);

			// Write out line & empty icons
			for (g=0; g<recursedNodes.length; g++) {
				if (recursedNodes[g] == 1) document.write("<img src=\"tree/image/img/line.gif\" align=\"absbottom\" alt=\"\" border=\"0\"/>");
				else  document.write("<img src=\"tree/image/img/empty.gif\" align=\"absbottom\" alt=\"\" border=\"0\"/>");
			}

			// put in array line & empty icons
			if (ls) recursedNodes.push(0);
			else recursedNodes.push(1);

			// Write out join icons
			if (hcn) {
				if (ls) {
					document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 1);\"><img id=\"join" + nodeValues[0] + "\" border=\"0\" src=\"tree/image/img/");
					 	if (ino) document.write("minus");
						else document.write("plus");
					document.write("bottom.gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
				} else {
					document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 0);\"><img id=\"join" + nodeValues[0] + "\" border=\"0\" src=\"tree/image/img/");
						if (ino) document.write("minus");
						else document.write("plus");
					document.write(".gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
				}
			} else {
				if (ls) document.write("<img src=\"tree/image/img/join.gif\" align=\"absbottom\" alt=\"\" border=\"0\" />");
				else document.write("<img src=\"tree/image/img/joinbottom.gif\" align=\"absbottom\" alt=\"\" border=\"0\" />");
			}

			// Start link
			document.write("<a href=\"javascript:userCheck('" + nodeValues[3] + "','" + nodeValues[2] + "');\">");
			
			// Write out folder & page icons
			if (hcn) {
				document.write("<img id=\"icon" + nodeValues[0] + "\"  border=\"0\" src=\"tree/image/img/folder"+imgid+"")
					if (ino) document.write("open");
				document.write(".gif\" align=\"absbottom\" alt=\"Folder\" />");
			} else document.write("<img id=\"icon" + nodeValues[0] + "\"  border=\"0\" src=\"tree/image/img/page"+imgid+".gif\" align=\"absbottom\" alt=\"Page\" />");
			
			// Write out node name
			document.write(nodeValues[2]);

			// End link
			document.write("</a><br />");
			
			// If node has children write out divs and go deeper
			if (hcn) {
				document.write("<div id=\"div" + nodeValues[0] + "\"");
					if (!ino) document.write(" style=\"display: none;\"");
				document.write(">");
				addNode(nodeValues[0], recursedNodes);
				document.write("</div>");
			}
			
			// remove last line or empty icon 
			recursedNodes.pop();
		}
	}
}
// Opens or closes a node
function oc(node, bottom) {
	var theDiv = document.getElementById("div" + node);
	var theJoin	= document.getElementById("join" + node);
	var theIcon = document.getElementById("icon" + node);
	
	if (theDiv.style.display == 'none') {
		if (bottom==1) theJoin.src = icons[3].src;
		else theJoin.src = icons[2].src;
		theIcon.src = icons[5].src;
		theDiv.style.display = '';
	} else {
		if (bottom==1) theJoin.src = icons[1].src;
		else theJoin.src = icons[0].src;
		theIcon.src = icons[4].src;
		theDiv.style.display = 'none';
	}
}
// Push and pop not implemented in IE(crap!    don? know about NS though)
if(!Array.prototype.push) {
	function array_push() {
		for(var i=0;i<arguments.length;i++)
			this[this.length]=arguments[i];
		return this.length;
	}
	Array.prototype.push = array_push;
}
if(!Array.prototype.pop) {
	function array_pop(){
		lastElement = this[this.length-1];
		this.length = Math.max(this.length-1,0);
		return lastElement;
	}
	Array.prototype.pop = array_pop;
}

</script>
<script type="text/javascript">
	var Tree = new Array;
	// nodeId | parentNodeId | nodeName | nodeUrl	
	var locale = "<%=SessionUtils.getLocale(request)%>";
	var modelName = "";
	if("zh"==locale){
		modelName="首页";
	}else{
		modelName="MainPage";
	}
	var modelURL = "frame/blank.html";
	var imageid = "7";
<%
	
	for(int i=0; i<list.size(); i++){				
		Map map = (Map) list.get(i);
		String functionid = (String) map.get("FUNCTIONID");
		String parentid = (String) map.get("PARENTID");
		String name = (String) map.get("NAME");
		String url =  (String)request.getContextPath() + "/"+(String) map.get("URL");
		String aaa = "Tree["+i+"]"+"='"+functionid+"|"+parentid+"|"+name+"|"+url+"'";
		out.println(aaa);
	}
%>

</script>
</head>
<body class="application-body">
<table width="220" border="0" align="left" cellpadding="0" cellspacing="0" style="margin-top:10px">
	<tr>
		<td align="left">
		<div style="position:absolute;top:0px;left:expression(document.body.clientWidth-this.offsetWidth);width:8px;height:100%;border-width:0px;">
		</div>
			<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
				<div id="tree"><script type="text/javascript">createTree(Tree,0,0,imageid,modelName,modelURL);</script></div>
			</table>
		</td>
  	</tr>
</table>

</body>
</html>
<%
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		if (dao != null) dao.disConnect();
	}
%>